<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<link rel="stylesheet" href="./tab栏切换style.css">
<body>
    <div class="tab">
        <div class="tab_nav">
            <h3>每日特价</h3>
            <ul>
               <li><a class="active" href="" data-id="1">精选</a></li>
               <li><a href="" data-id="2" >美食</a></li>
               <li><a href="" data-id="3" >百货</a></li>
               <li><a href="" data-id="4" >个护</a></li>
               <li><a href="" data-id="5" >预告</a></li> 
            </ul>
        </div>
        <div class="tab_content">
            <div class="item active"><img src="./轮播图images/hzw01.jpg" alt=""></div>
            <div class="item"><img src="./轮播图images/hzw02.jpg" alt=""></div>
            <div class="item"><img src="./轮播图images/hzw03.jpg" alt=""></div>
            <div class="item"><img src="./轮播图images/hzw04.jpg" alt=""></div>
            <div class="item"><img src="./轮播图images/hzw05.jpg" alt=""></div>
        </div>
    </div>
    <script>
        const ul=document.querySelector('.tab_nav ul')
        // const item=document.querySelectorAll('.tab_content .item')
        ul.addEventListener('click',function(e){
            if(e.target.tagName==='A'){
                document.querySelector('.tab_nav .active').classList.remove('active')
                e.target.classList.add('active')
                const son= +e.target.dataset.id
                document.querySelector('.tab_content .active').classList.remove('active')
                document.querySelector(`.tab_content .item:nth-child(${son+1})`).classList.add('active')
            }
        })
    </script>
</body>
</html>